import BaseService from "./BaseService";

/**
 * 产品service
 */
export default class ProductService extends BaseService {
    
    constructor() {
        super();
    }

    /**
     * 返回list
     */
    list() {
      const url = `${this.host}/products`;
      return this.get(url).then(data => data != '' ? data : Promise.reject('NO_PRODUCT'));
    }
    
    detail(productId, unionid) {
      const url = `${this.host}/products/${productId}/units?unionid=${unionid}`;
      return this.get(url).then(data => data != '' ? data : Promise.reject('NO_PRODUCT_DETAIL'));
    }

    unitDetail(productId, unitId) {
      const url = `${this.host}/products/${productId}/units/${unitId}`;
      return this.get(url).then(data => data != '' ? data : Promise.reject('NO_PRODUCT_UNIT_DETAIL'));
    }

    listByPersion(unionid) {
      const url = `${this.host}/user-products?unionid=${unionid}`;
      return this.get(url).then(data => data != '' ? data : Promise.reject('NO_USER_PRODUCT'));
    }

    loadByPersion(bookid, unionid) {
      const url = `${this.host}/user-products/${bookid}?unionid=${unionid}`;
      return this.get(url).then(data => data != '' ? data : Promise.reject('NO_USER_PRODUCT_DETAIL'));
    }
}
